FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }}
{% block labels %}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"
{% endblock %}

{% block grafana_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{{ macros.enable_extra_repos(['grafana']) }}

{% set grafana_packages = ['grafana'] %}

{{ macros.configure_user(name='grafana', homedir='/usr/share/grafana') }}

{{ macros.install_packages(grafana_packages | customizable("packages")) }}

WORKDIR /usr/share/grafana

COPY grafana_sudoers /etc/sudoers.d/kolla_grafana_sudoers
COPY extend_start.sh /usr/local/bin/kolla_extend_start

{% block grafana_plugins_install %}

{% set grafana_default_plugins = ['gnocchixyz-gnocchi-datasource', 'grafana-opensearch-datasource']  %}
{% set grafana_plugins =  grafana_default_plugins | customizable("plugins") %}

{% if grafana_plugins | length > 0 %}
RUN {{ (['grafana-cli plugins install %s'] * grafana_plugins | length ) | join(' && ') | format(*grafana_plugins) }}
{% endif %}
{% endblock %}

RUN chmod 750 /etc/sudoers.d \
    && chmod 440 /etc/sudoers.d/kolla_grafana_sudoers \
    && chmod 644 /usr/local/bin/kolla_extend_start

{% block grafana_footer %}{% endblock %}
{% block footer %}{% endblock %}

USER grafana
